<?php
class Zendvn_Validate_Captcha extends Zend_Validate_Abstract{

	const CAPTCHA_NOT_EQUAL  = 'captchaNotEqual';
    
    protected $_messageTemplates = array(
        self::CAPTCHA_NOT_EQUAL   => "'%value%' security code is wrong",        
    );
    
    private $_captchaID;
	
    public function __construct($captchaID = null){
    	$this->_captchaID = $captchaID;
    }
	
	public function isValid($value){
		$namespace = 'Zend_Form_Captcha_' . $this->_captchaID;
		$ss = new Zend_Session_Namespace($namespace);
		$word = $ss->word;		
		unset($ss);
		
		if($value !== $word){
			$this->_error(self::CAPTCHA_NOT_EQUAL,$value);
			return false;
		}
		
		return true;
	}
}